package com.zengjianjun.push.msg.platform;

import com.zengjianjun.push.msg.enums.PushMsgPlatformEnum;
import com.zengjianjun.push.msg.exception.PushMsgException;
import com.zengjianjun.push.msg.platform.param.BasePushMsgParam;
import com.zengjianjun.push.msg.platform.wecom.WeComClient;
import com.zengjianjun.push.msg.properties.PushMsgProperties;
import lombok.extern.slf4j.Slf4j;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

/**
 * @author zengjianjun
 */
@Slf4j
public class PushMsgClient implements IPushMsgClient {

    @Resource
    private PushMsgProperties pushMsgProperties;
    @Resource
    private WeComClient weComClient;

    private IPushMsgClient client;

    @PostConstruct
    public void init() {
        log.info("push msg init start...");
        PushMsgPlatformEnum type = pushMsgProperties.getType();
        if (type == null) {
            throw PushMsgException.build("push msg init error: type is null");
        }
        if (type == PushMsgPlatformEnum.WeCom) {
            client = weComClient;
        } else {
            throw PushMsgException.build("push msg init error: unsupported push msg type");
        }
        log.info("push msg load {}", type.name());
        log.info("push msg init success...");
    }

    @Override
    public void sendMsg(BasePushMsgParam param) {
        client.sendMsg(param);
    }
}
